import * as types from './../constants/ActionTypes';

/*
 * 手机验证码
 ================================================================*/
export function fetchTicket(phone) {
    return (dispatch) => {
        let payload = {
            ticket_status: 0,
            message: '加载中'
        };
        dispatch({
            payload,
            type: [types.FETCH_TICKET, types.FETCH_TICKET_SUCCESS, types.FETCH_TICKET_FAILURE],
                meta: {
                    fetch: [`members/getphonevalid`, {
                        method: 'post',
                        body: `phone=${phone}`
                    }]
                }
        });
    };
}

/*
 * 图片验证码
 ================================================================*/
export function fetchImgTicket() {
    return (dispatch) => {
        let payload = {
            imgticket_status: 0,
            message: '加载中'
        };
        dispatch({
            payload,
            type: [types.FETCH_IMGTICKET, types.FETCH_IMGTICKET_SUCCESS, types.FETCH_IMGTICKET_FAILURE],
                meta: {
                    fetch: [`member/bindingimg`, {
                        method: 'get'
                    }]
                }
        });
    };
}

/*
 * 手机验证码验证
 ================================================================*/
export function validate(phone, captcha) {
    return (dispatch) => {
        let payload = {
            validate_status: 0,
            message: '加载中',
            phone: phone,
            captcha: captcha
        };
        dispatch({
            payload,
            type: [types.TICKET_VALIDATE, types.TICKET_VALIDATE_SUCCESS, types.TICKET_VALIDATE_FAILURE],
                meta: {
                    fetch: [`members/phonevalid`, {
                        method: 'post',
                        body: `phone=${phone}&captcha=${captcha}`
                    }]
                }
        });
    };
}